import nltk
import os

def download_nltk_resources():
    """下载LlamaIndex所需的NLTK资源"""
    print("正在下载NLTK资源...")
    
    # 下载stopwords资源
    try:
        nltk.download('stopwords', quiet=True)
        print("✓ stopwords资源下载完成")
    except Exception as e:
        print(f"✗ stopwords资源下载失败: {e}")
    
    # 下载punkt资源
    try:
        nltk.download('punkt', quiet=True)
        print("✓ punkt资源下载完成")
    except Exception as e:
        print(f"✗ punkt资源下载失败: {e}")
    
    # 下载其他可能需要的资源
    resources = ['averaged_perceptron_tagger', 'maxent_ne_chunker', 'words']
    for resource in resources:
        try:
            nltk.download(resource, quiet=True)
            print(f"✓ {resource}资源下载完成")
        except Exception as e:
            print(f"✗ {resource}资源下载失败: {e}")
    
    print("\nNLTK资源下载完成！")

if __name__ == "__main__":
    download_nltk_resources() 